<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../../_template.xhtml"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:p="http://primefaces.org/ui">

    <ui:define name="centro">
        <h:form> 
            <p:outputLabel value="Fluxo de Caixa" style="font-size: x-large; margin-left: 25px" styleClass="labelInserir" /> 

            <p:fieldset styleClass="fieldsetInsert" style=" margin-left: 25px">
                <h:panelGrid columns="5" style="margin-bottom: 10px" >
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 5px; text-align: left" value="Conta" />
                        <p:selectOneMenu value="#{fluxoCaixaBean.conta}" converter="entityConverter"
                                         required="true" requiredMessage="Informe uma conta">
                            <f:selectItem itemLabel="Escolha uma opção" noSelectionOption="true" />
                            <f:selectItems value="#{fluxoCaixaBean.contas}" var="conta" itemLabel="#{conta.nome}"/>
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 5px; text-align: left" value="Data de Início" />
                        <p:calendar pattern="dd/MM/yyyy" yearRange="c-100:c+100" navigator="true" readonlyInput="true"
                                    value="#{fluxoCaixaBean.dataInicio}" maxdate="#{clienteBean.dataAtual}" 
                                    required="true" requiredMessage="Informe a data de início da pesquisa." />
                    </h:panelGrid>
                    <h:panelGrid columns="1" >
                        <p:outputLabel style="margin-left: 5px; text-align: left" value="Data Fim" />
                        <p:calendar pattern="dd/MM/yyyy" yearRange="c-100:c+100" navigator="true" readonlyInput="true"
                                    value="#{fluxoCaixaBean.dataFim}" maxdate="#{clienteBean.dataAtual}"
                                    required="true" requiredMessage="Informe a data fim da pesquisa." />
                    </h:panelGrid>
                </h:panelGrid>
            </p:fieldset>
            
            <h:panelGrid columns="2" rendered="#{not empty fluxoCaixaBean.lancamentos}">
                <p:outputLabel value="Saldo: " style="margin-left: 795px; margin-bottom: 20px; margin-top: 20px"/>
                <p:outputLabel value="#{fluxoCaixaBean.conta.saldo}" rendered="#{fluxoCaixaBean.lancamentos.size() > 0}">
                    <f:convertNumber type="currency" locale="pt_br" />
                </p:outputLabel>
            </h:panelGrid>
            
            <p:dataTable styleClass="dados" value="#{fluxoCaixaBean.lancamentos}" rendered="#{not empty fluxoCaixaBean.lancamentos}" var="lancamento" emptyMessage="Nenhum registro encontrado!"  style=" margin-left: -75px">
                <p:column style="text-align: center;" headerText="Data do Vencimento" >
                    <h:outputText value="#{lancamento.dataPagamento}">
                        <f:convertDateTime pattern="dd/MM/yyyy" /> 
                    </h:outputText>
                </p:column>
                <p:column style="text-align: center;" headerText="Nr Documento" >   
                    <h:outputText value="#{lancamento.documento.nrDocumento}"/>
                </p:column>
                <p:column style="text-align: center;" headerText="Tipo"  >   
                    <h:outputText value="#{lancamento.documento.tipoDocumento.descricao}" rendered="#{not empty lancamento.documento.tipoDocumento}"/>
                    <h:outputText value="#{lancamento.documento.notaFiscal.tipoNotaFiscal.descricao}" rendered="#{not empty lancamento.documento.notaFiscal.tipoNotaFiscal}"/>
                </p:column>
                <p:column style="text-align: left; width: 200px" headerText="Origem/Destino" >   
                    <h:outputText value="#{lancamento.documento.pessoa.nome}"/>
                </p:column>
                <p:column style="text-align: center;" headerText="Situação" >
                    <h:outputText value="#{lancamento.situacao}"/>
                </p:column>
                <p:column style="text-align: right;" headerText="Valor" >
                    <h:outputText value="#{lancamento.valor}">
                        <f:convertNumber type="currency" locale="pt_br" />
                    </h:outputText>
                </p:column>
                <p:column style="width: 10px; text-align: center" headerText="Tipo" >
                    <h:outputText value="#{lancamento.tipo eq 'CREDITO' ? 'C' : 'D'}"/>
                </p:column>

            </p:dataTable>
            <br />
            <p:commandButton value="Consultar" action="#{fluxoCaixaBean.listarLancamentos}" icon="ui-icon-search" ajax="false" style="margin-left: 30px;"/>
            <p:commandButton value="Voltar" action="#{fluxoCaixaBean.voltar}" immediate="true" ajax="false" style="margin-left: 30px;" icon="ui-icon-arrowreturnthick-1-w"/>   
        </h:form>
    </ui:define>

</ui:composition>
